package com.qf.web;

import com.qf.domain.Student;
import com.qf.service.Service;
import com.qf.service.impl.ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginn")
public class ZhuCe extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        Service service=new ServiceImpl();
        Student deng = service.deng(username, password);
        if (deng!=null){
            resp.sendRedirect(req.getContextPath()+"/admin/main.jsp");
        }else {
            req.setAttribute("loginError","用户名或者密码错误");
            req.getRequestDispatcher("/admin/login.jsp").forward(req,resp);

        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req, resp);
    }
}
